﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Additional
using System.Runtime.Serialization;
using System.Collections.ObjectModel;

namespace DO.Common.Messages
{
    [DataContract]
    public class Response
    {
        #region Constructors
        public Response() : this(0) { }

        public Response(long entityIdentity)
        {
            EntityIdentityInstance = entityIdentity;
        }
        #endregion

        #region Private Serializable members
        [DataMember]
        private BusinessExceptionDTO BusinessExceptionDTOInstance;

        [DataMember]
        private readonly IList<BusinessWarning> BusinessWarningList = new List<BusinessWarning>();

        [DataMember]
        private readonly long EntityIdentityInstance;

        #endregion

        #region Public Methods
        public void AddBusinessException(BusinessException exception)
        {
            BusinessExceptionDTOInstance = new BusinessExceptionDTO(exception.ExceptionType, exception.Message, exception.StackTrace);
        }

        public void AddBussinessWarnings(IEnumerable<BusinessWarning> warnings)
        {
            warnings.ToList().ForEach(warning => BusinessWarningList.Add(warning));
        }
        #endregion

        #region Public Getters
        public bool HasWarning
        {
            get { return this.BusinessWarningList.Count > 0;  }
        }

        public IEnumerable<BusinessWarning> BusinessWarnings
        {
            get { return new ReadOnlyCollection<BusinessWarning>(this.BusinessWarningList);}
        }

        public long EntityIdentity
        {
            get { return this.EntityIdentityInstance;  }
        }

        public bool HasException
        {
            get { return BusinessExceptionDTOInstance != null; }
        }

        public BusinessExceptionDTO BusinessExceptionDto
        {
            get { return this.BusinessExceptionDTOInstance; }
        }
        #endregion
    }
}
